package com.cg.service;

import com.cg.entity.Category;
import com.cg.entity.StatisticsCircle;
import com.cg.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    public List<StatisticsCircle> circle(String createdId) {
       List<StatisticsCircle> statisticsCircles=categoryMapper.circle(createdId);
        return statisticsCircles;
    }

//

    public int insert(Category category) {
        Category category1 = categoryMapper.ifRepeat(category.getCreatedBy(), category.getCategoryName());
        if (category1 == null) {
            int a = categoryMapper.insert(category);
            return a;
        }
        return 0;
    }

    public int update(Category category) {
        Category category1 = categoryMapper.ifRepeat(category.getCreatedBy(), category.getCategoryName());
        if (category1 == null) {
            int a = categoryMapper.update(category);
            return a;
        } else {
            return 0;
        }
    }
//    public List<Category> selectList1(String username){
//        List<Category> list=categoryMapper.selectByPrimaryKey(username);
//        System.out.println(list);
//        return list;
//    }

    public int deleteOne(int categoryId) {
        int a = categoryMapper.deleteOne(categoryId);
        return a;
    }

    public List<Category> selectList(String createdBy) {
        List<Category> list = categoryMapper.selectList(createdBy);
        return list;
    }
}
